/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.asseco.mio.search;

import com.asseco.mio.codex.AssMark;
import com.asseco.persistence.service.HibernateUtil;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author konstantin.sivakov
 */
public class AssMarkSearch {
    
    
    public String getDescription(String s){
        
        String resultString;
        List result;
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
//        Criteria criteria = session.createCriteria(AssMark.class)
//         .setProjection(Projections.projectionList()
//        .add(Projections.property("assMarkName")))
//         .add(Restrictions.and(Restrictions.ge("numAssMarkFrom", Float.parseFloat(s)),Restrictions.le("numAssMarkTo",  Float.parseFloat(s))));
        
        ProjectionList proj = Projections.projectionList();
        proj.add(Projections.property("assMarkName"));
        
         Criteria criteria = session.createCriteria(AssMark.class)
         .setProjection(proj).add(Restrictions.and(Restrictions.lt("numAssMarkFrom", Float.parseFloat(s)),Restrictions.gt("numAssMarkTo",  Float.parseFloat(s))));
        
        result = criteria.list();
        resultString = (String)result.get(0);
        System.out.println("TEST"+resultString);
        return resultString;
    }

}
